package com.dianmi.seckill.common.utils;

import com.dianmi.seckill.common.advice.ResponseCode;
import com.dianmi.seckill.common.advice.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.temporal.Temporal;

/**
 * @author xieqiaofu
 * @date 2020/12/4
 */
@Slf4j
public class AssertUtil {

    public static void allow(boolean isAllow, String msg) {
        if (!isAllow) {
            log.warn("断言不通过：{}", msg);
            throw new ServiceException(ResponseCode.SERVICE_ERROR, msg);
        }
    }

    public static void notEmptyElements(String msg, String... elements) {
        for (String element : elements) {
            if (!StringUtils.hasText(element)) {
                throw new ServiceException(ResponseCode.SERVICE_ERROR, msg);
            }
        }
    }

    public static void leastOneNotEmptyElements(String msg, String... elements) {
        boolean flag = false;
        for (String element : elements) {
            if (StringUtils.hasText(element)) {
                flag = true;
            }
        }
        if (!flag) {
            throw new ServiceException(ResponseCode.SERVICE_ERROR, msg);
        }
    }

    public static void before(LocalDate start, Temporal end) {


    }
}
